﻿using B.S.DataBase.MyProject.Domain.Sales;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.SalesCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.SalesCommandHandler
{
    public class GetOneDeliveryCommandHandler : IRequestHandler<GetOneDeliveryCommand, APIResult<List<DeliveryNotice>>>
    {
        private readonly IBaseRepository<DeliveryNotice> delivRep;
        public GetOneDeliveryCommandHandler(IBaseRepository<DeliveryNotice> delivRep)
        {
            this.delivRep = delivRep;
        }
        public Task<APIResult<List<DeliveryNotice>>> Handle(GetOneDeliveryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<DeliveryNotice>> result = new APIResult<List<DeliveryNotice>>();
            result.Code = APIEnum.成功;
            result.Msg = APIEnum.查询成功.ToString();
            var list= delivRep.GetAll().Result;
            list = list.OrderByDescending(x => x.NoticeId);
            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
